package leraning.url;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public class URL1 {
	public static void main(String[] args) {
		String path = "http://img02.sogoucdn.com/app/a/100520093/ac75323d6b6de243-1aa6516885d490be-714b6a3001f6845eb9b642ddedc138d3.jpg";
		try {
			URL url = new URL(path);
			InputStream is=url.openStream();
			OutputStream os=new FileOutputStream("img/img3.jpg");
			byte[] buf=new byte[1024];
			int len=0;
			while((len=is.read(buf))!=-1){
				os.write(buf, 0, len);
				os.flush();
			}
			System.out.println("finished");
			is.close();
			os.close();
			
//            System.out.println(url.getPath());
//            System.out.println(url.getPort());
//            System.out.println(url.getProtocol());
//            System.out.println(url.getFile());
            
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
